import { Injectable } from '@angular/core';
import {Hero} from "../class/hero";
import {HEROES} from "../class/mock-heros";
@Injectable()
export class HeroService {
  getHeros():Promise<Hero[]>{
      return Promise.resolve(HEROES);
  }
  getHerosSlowly():Promise<Hero[]>{
    return new Promise(resolve=>{
      setTimeout(()=>{
        resolve(this.getHeros())
      },1000);
    })
  }
  getHero(id: number): Promise<Hero> {
    return this.getHeros()
      .then(heroes => heroes.find(hero => hero.id === id));
  }
}
